package cn.com.cdb.ldms.exception;

import lombok.Getter;
import lombok.Setter;

import java.io.Serial;
import java.util.Arrays;
import java.util.stream.Collectors;

/**
 * 业务异常.
 *
 * @author jizi
 * @description 业务级异常基类
 */

public class BusinessException extends CometPlatformException {

    @Serial
    private static final long serialVersionUID = -43523452345L;

    @Setter
    @Getter
    private String code;

    /**
     * Instantiates a new Business exception.
     */
    public BusinessException() {
        super();
    }

    /**
     * Instantiates a new Business exception.
     *
     * @param errorMsg the error msg
     */
    public BusinessException(String errorMsg) {
        super(errorMsg);
    }


    /**
     * Instantiates a new Business exception.
     *
     * @param errorCode          the error code
     * @param errorMessageParams the error message params
     */
    public BusinessException(ErrorCode errorCode, Object... errorMessageParams) {
        super(Arrays.stream(errorMessageParams).map(Object::toString).collect(Collectors.joining(", ")));
        this.code = errorCode.getErrorCode();
    }

}
